package bancosys.tec.rtm.impl.diagnostician;

import java.io.InputStream;

import org.jdom.input.SAXBuilder;

import bancosys.tec.rtm.diagnostician.AbstractDiagnostician;
import bancosys.tec.rtm.diagnostician.DiagnosisBean;

/**
 * Diagnosticador que verifica se um xml está bem estruturado.
 * 
 * @author Evaristo
 * @version $Id:$ <b>Created on: </b> 02/02/2007
 */
public class XmlValidatorDiagnostician extends AbstractDiagnostician {

    private String xmlName;

    private InputStream inputStream;

    /**
     * Construtor. Como um inputStream nao foi passado o arquivo sera carregado do classpath.
     * 
     * @param xmlName nome do arquivo xml.
     */
    public XmlValidatorDiagnostician(String xmlName) {
        this.xmlName = xmlName;
        this.inputStream = this.getClass().getClassLoader().getResourceAsStream(xmlName);
    }

    /**
     * Construtor do Diagnosticador de Estrutura de Xml.
     * 
     * @param xmlName String
     * @param inputStream InputStream
     */
    public XmlValidatorDiagnostician(String xmlName, InputStream inputStream) {
        this.xmlName = xmlName;
        this.inputStream = inputStream;
    }

    /**
     * {@inheritDoc}
     */
    public String getName() {
        return "Validador de XML (" + xmlName + ")";
    }

    /**
     * {@inheritDoc}
     */
    @Override
    protected boolean fillDiagnosisBean(DiagnosisBean bean) throws Exception {

        SAXBuilder builder = new SAXBuilder();
        builder.build(this.inputStream);
        return true;
    }
}